package com.tnf.bc.bground.certificate.filter;

import com.alibaba.fastjson.JSON;
import com.tnf.bc.bground.common.utils.resultutil.ApiResponse;
import com.tnf.bc.bground.common.utils.resultutil.WebUtils;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * @description: //无权限访问
 * @author: lzl
 * @create: 2022-11-18 16:58
 **/
@Component
public class FailAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
        ApiResponse apiResponse = new ApiResponse(HttpStatus.FORBIDDEN.value(), "您的权限不足");
        String jsonString = JSON.toJSONString(apiResponse);
        WebUtils.rendrString(httpServletResponse, jsonString);
    }
}